﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Xml.Serialization;

namespace BDSim
{
    /// <summary>
    /// 地面段子集
    /// </summary>
    public class SubGroundSegment : BDSimObject
    {
        public SubGroundSegment()
        {
            _DataProvider.Parent = this;
            _DataProvider.DefineCommand();
            Menu.ItemsSource = _DataProvider.MenuCommandList;
        }

        #region 字段
        GroundSegment _Parent;

        [XmlIgnore, Browsable(false)]
        public GroundSegment Parent
        {
            get { return _Parent; }
            set { _Parent = value; }
        }

        private SubGroundSegmentDataProvider _DataProvider = new SubGroundSegmentDataProvider();

        /// <summary>
        /// 地面站类型(BD/GPS/GALILEO/GLONASS)
        /// </summary>
        private EConstellationType _Type;

        /// <summary>
        /// 获取该导航星座地面段中的所有主控站集+监测站集+注入站集
        /// </summary>
        ObservableCollection<StationCollection> _GroundList = new ObservableCollection<StationCollection>();
       
        #endregion

        #region 属性

        /// <summary>
        /// 获取该导航星座地面段中的所有主控站集+监测站集+注入站集
        /// </summary>
        [XmlIgnore, Browsable(false)]
        public ObservableCollection<StationCollection> GroundList
        {
            get { return _GroundList; }
            set { _GroundList = value;}
        }

        /// <summary>
        /// 站名
        /// </summary>
        [ReadOnly(true), Category("基本信息"), Description("")]
        public string Name
        {
            get { return _Name; }
            set { _Name = value; NotifyPropertyChanged("Name"); }
        }
        
        /// <summary>
        /// 地面站所属星座类型(BD/GPS/GALILEO/GLONASS)
        /// </summary>
        [XmlAttribute, ReadOnly(true)]
        public EConstellationType Type
        {
            get { return _Type; }
            set { _Type = value; }
        }

        #endregion

        #region 初始化
        public override void Init()
        {
            //给_GroundList每一个对象（item）赋值
            foreach (var item in _GroundList)
            {
                item.Parent = this;
            }
            base.Init();
            foreach (var item in GroundList)
            {
                item.Init();
            }
        }
        #endregion

        #region 单步运行
        public override void StepRun()
        {
            base.StepRun();
            foreach (var item in GroundList)
            {
                item.StepRun();
            }
        }
        #endregion

        internal void AddStationCollection(StationCollection stationCollection)
        {
            stationCollection.Parent = this;
            GroundList.Add(stationCollection);
        }
    }
}
